﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Siege.SiegeEventManager
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Library;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.Siege
{
  public class SiegeEventManager
  {
    [SaveableField(1)]
    private MBList<SiegeEvent> _siegeEvents;

    internal static void AutoGeneratedStaticCollectObjectsSiegeEventManager(
      object o,
      List<object> collectedObjects)
    {
      ((SiegeEventManager) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      collectedObjects.Add((object) this._siegeEvents);
    }

    internal static object AutoGeneratedGetMemberValue_siegeEvents(object o)
    {
      return (object) ((SiegeEventManager) o)._siegeEvents;
    }

    public MBReadOnlyList<SiegeEvent> SiegeEvents => (MBReadOnlyList<SiegeEvent>) this._siegeEvents;

    public SiegeEventManager() => this._siegeEvents = new MBList<SiegeEvent>();

    public SiegeEvent StartSiegeEvent(Settlement settlement, MobileParty besiegerParty)
    {
      SiegeEvent siegeEvent = new SiegeEvent(settlement, besiegerParty);
      this._siegeEvents.Add(siegeEvent);
      settlement.Party.SetVisualAsDirty();
      return siegeEvent;
    }

    public void Tick(float dt)
    {
      for (int index = 0; index < this._siegeEvents.Count; ++index)
      {
        if (this._siegeEvents[index].ReadyToBeRemoved)
        {
          this._siegeEvents[index] = this._siegeEvents[this._siegeEvents.Count - 1];
          this._siegeEvents.RemoveAt(this._siegeEvents.Count - 1);
          --index;
        }
        else
          this._siegeEvents[index].Tick(dt);
      }
    }
  }
}
